My code below is causing errors with missing "}". But I don't know how to fix it, all my brackets close from what I can see. Could someone take a look & help? Thanks in advance.
@using umbraco.MacroEngines
@inherits umbraco.MacroEngines.DynamicNodeContext
@* get strings from url, if existing *@
@{
string collect = String.Format("{0}", Request.QueryString["Bottle"]);
var rows = 0;
var rowNum = 0;
var numInRow = 3;
var tr = 0;
if (!string.IsNullOrEmpty(Request.QueryString["Bottle"])) {
var rep = CurrentModel.DescendantsOrSelf().Items.SingleOrDefault(x => x.Name == collect);
if (rep != null) {
for (int i = 0; i rep.Count() / numInRow; i++) {
int s = i * numInRow;
if (rows == 0) {
rowNum++;
}
if (rows == 1) {
rowNum--;
}
foreach (var node in rep.Skip(s).Take(numInRow)) {
@* DO LOTS WITH EVERY ITEM *@
}
Hey James,
I'm not sure about missing a closing brace, but in the for loop it's missing a conditional.
The fix
i <some conditional> rep.Count()
Rather than
i rep.Count()
Complete code
@using umbraco.MacroEngines
@inherits umbraco.MacroEngines.DynamicNodeContext
@* get strings from url, if existing *@
@{
string collect = String.Format("{0}", Request.QueryString["Bottle"]);
var rows = 0;
var rowNum = 0;
var numInRow = 3;
var tr = 0;
if (!string.IsNullOrEmpty(Request.QueryString["Bottle"])) {
var rep = CurrentModel.DescendantsOrSelf().Items.SingleOrDefault(x => x.Name == collect);
if (rep != null) {
for (int i = 0; i <some conditional> rep.Count() / numInRow; i++) {
int s = i * numInRow;
if (rows == 0) {
rowNum++;
}
if (rows == 1) {
rowNum--;
}
foreach (var node in rep.Skip(s).Take(numInRow)) {
@* DO LOTS WITH EVERY ITEM *@
}
if (rows == 0){rows++;} else {rows--;}
tr++;
}
}
}
}
Thanks Jamie! Didn't see that. I'm now getting this:
Error occured
...\635146033346293678_Results.cshtml(18): error CS1061: 'umbraco.MacroEngines.DynamicNode' does not contain a definition for 'Count' and no extension method 'Count' accepting a first argument of type 'umbraco.MacroEngines.DynamicNode' could be found (are you missing a using directive or an assembly reference?)
Am I missing a @using or @inherit reference at the top?
Code block is missing "}" character??
My code below is causing errors with missing "}". But I don't know how to fix it, all my brackets close from what I can see. Could someone take a look & help? Thanks in advance.
Hey James, I'm not sure about missing a closing brace, but in the for loop it's missing a conditional.
The fix
Rather than
Complete code
I hope this helped, mate.
Jamie
Thanks Jamie! Didn't see that. I'm now getting this:
Error occured
...\635146033346293678_Results.cshtml(18): error CS1061: 'umbraco.MacroEngines.DynamicNode' does not contain a definition for 'Count' and no extension method 'Count' accepting a first argument of type 'umbraco.MacroEngines.DynamicNode' could be found (are you missing a using directive or an assembly reference?)
Am I missing a @using or @inherit reference at the top?
Hi James, Nope not at all. It's because you're setting rep via
which will always return a single node. If you want to return a collection of nodes you should use
Count is only available to IEnumerables or collections.
Jamie
is working on a reply...